﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;


public partial class QuarterPlan_DisplayAttachment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int Id = Utility.HttpHelp.getParamsInt("Id");
        object[] _value = new object[1];
        DataTable dt;
        _value[0] = Id;
        int TypeId = Utility.HttpHelp.getParamsInt("TypeId");
        if (TypeId == 0)
        {
            dt = new BLL.FishBoneDiagram().GetFishBoneById(_value);
        }
        else
        {
            dt = new BLL.YearIntroduction().GetYearIntroductionById(_value);
        }
        if (dt.Rows.Count > 0)
        {
            if (dt.Rows[0]["UploadUrl"].ToString().ToLower().Contains(".jpg")
                || dt.Rows[0]["UploadUrl"].ToString().ToLower().Contains(".gif")
                || dt.Rows[0]["UploadUrl"].ToString().ToLower().Contains(".png")
                || dt.Rows[0]["UploadUrl"].ToString().ToLower().Contains(".bmp"))
            { 
                this.Img.ImageUrl = @"../../" + dt.Rows[0]["UploadUrl"].ToString().Substring(dt.Rows[0]["UploadUrl"].ToString().IndexOf("Upload"));
            }
            else
            { 
                FileDownload(dt.Rows[0]["UploadUrl"].ToString());
            }
        }
    }



    ///   <summary>   
    ///   文件下载   
    ///   </summary>   
    ///   <param   name="FullFileName"></param>   
    private void FileDownload(string strFileName)
    {

        FileInfo DownloadFile = new FileInfo(strFileName);
        if (!DownloadFile.Exists)
        {
            Utility.HttpHelp.alert("无附件,请与管理员联系", Page);
            return;
        }
        try
        {
            FileStream fs = File.Open(strFileName, FileMode.Open);
            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
            fs.Close();
            
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "filename=" + strFileName);
            Response.AddHeader("content-length", buffer.Length.ToString());
            Response.BinaryWrite(buffer);
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        finally
        {
            Response.Flush();
            Response.Close();
            Response.End();
        }

    } 
}